** Clearing Stata memory
capture log close
clear all
set more off, perm
set seed 1234

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// Table O.3: Predicting Power of P1 Scores for P2 Scores //////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

** Opening Phase 2 norm_scores dataset 
use "Work Data/Gender_Phase2_long.dta",clear

*********************************************************************************
**************** Main sample ****************************************************
*********************************************************************************

* 1) Only years before the affirmative action took place
drop if aa_year==1
tab year
drop if year==2000
tab year

* 2) Drop Portuguese and Foreign Language (in Phase 1 there is no Portuguese or Foreign Language exams - For Portuguese Phase 1 has an essay)
 tab subject, sum(norm_p1score)
 drop if subject=="lang" | subject=="port" 
 tab subject, sum(norm_p1score)
 drop Language Portuguese 

***************************
* Explanatory Power of P1 
***************************

label var norm_p1score "P1 normalized subject-specific scores"
label var p1score "Raw Phase 1 scores"

estimates clear

reg score i.year, cluster(inscri2) 
estimates store reg1
reg score p1score i.year, cluster(inscri2)
estimates store reg2
reghdfe score, cluster(inscri2) absorb(inscri2)
estimates store reg3
reghdfe score p1score, cluster(inscri2) absorb(inscri2)
estimates store reg4

estadd local year_fe "No":  reg3 reg4
estadd local year_fe "Yes": reg1 reg2 

estadd local ind_fe "No": reg1 reg2 
estadd local ind_fe "Yes": reg3 reg4

* Tex Panel A
esttab reg1 reg2 reg3 reg4 using "Output/p1_predictor_alt.tex", se star(* 0.10 ** 0.05 *** 0.01) nogap ///
stats(N N_clust r2_a sep year_fe ind_fe, fmt(%9.0fc %9.0fc %4.3fc %1s %3s %3s %3s) ///
 labels("Number of observations"  "Number of applicants" "$\bar{R}^2$" " " "Year FE" "Individual FE")) ///
 b(%7.3f) se(%7.3f)  booktabs replace f label nomtitle collabels(none) keep(p1score) ///
refcat(p1score " \\ \multicolumn{5}{l}{\textit{Panel A: Phase 2 raw subject-specific scores}} \\", nolabel)

estimates clear

reg norm_score, cluster(inscri2) 
estimates store reg1
reg norm_score norm_p1score, cluster(inscri2)
estimates store reg2
reghdfe norm_score, cluster(inscri2) absorb(inscri2)
estimates store reg3
reghdfe norm_score norm_p1score, cluster(inscri2) absorb(inscri2)
estimates store reg4

estadd local year_fe "No":  reg1 reg2 reg3 reg4

estadd local ind_fe "No": reg1 reg2 
estadd local ind_fe "Yes": reg3 reg4

* Tex Panel B
esttab reg1 reg2 reg3 reg4 using "Output/p1_predictor_alt.tex", se star(* 0.10 ** 0.05 *** 0.01) nogap ///
stats(N N_clust r2_a sep year_fe ind_fe, fmt(%9.0fc %9.0fc %4.3fc %1s %3s %3s %3s) ///
 labels("Number of observations"  "Number of applicants" "$\bar{R}^2$" " "  "Year FE" "Individual FE")) ///
 b(%7.3f) se(%7.3f)  booktabs append f label nomtitle  nonumber collabels(none) keep(norm_p1score) ///
refcat(norm_p1score " \\ \multicolumn{5}{l}{\textit{Panel B: Phase 2 normalized subject-specific scores}} \\", nolabel)




